<!DOCTYPE html>



  


<html class="theme-next pisces use-motion" lang="">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/blog/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/blog/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/blog/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/blog/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/blog/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/blog/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Hexo, NexT" />










<meta name="description" content="###Java Retrofit2使用本文使用eclipse编辑器，gradle依赖jar，如若未配置此环境，请转Java Eclipse配置gradle编译项目配置好环境后再查看此文  在build.gradle文件中添加一下依赖123compile &amp;apos;com.squareup.retrofit2:adapter-rxjava:2.3.0&amp;apos;compile &amp;apos;com.">
<meta name="keywords" content="Android、iOS、Web、React Native">
<meta property="og:type" content="article">
<meta property="og:title" content="Java-Retrofit2使用">
<meta property="og:url" content="http://yoursite.com/blog/2018/08/06/Java/Java-Retrofit2使用/index.html">
<meta property="og:site_name" content="凌浩雨_博客">
<meta property="og:description" content="###Java Retrofit2使用本文使用eclipse编辑器，gradle依赖jar，如若未配置此环境，请转Java Eclipse配置gradle编译项目配置好环境后再查看此文  在build.gradle文件中添加一下依赖123compile &amp;apos;com.squareup.retrofit2:adapter-rxjava:2.3.0&amp;apos;compile &amp;apos;com.">
<meta property="og:locale" content="default">
<meta property="og:updated_time" content="2018-08-06T10:46:00.843Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Java-Retrofit2使用">
<meta name="twitter:description" content="###Java Retrofit2使用本文使用eclipse编辑器，gradle依赖jar，如若未配置此环境，请转Java Eclipse配置gradle编译项目配置好环境后再查看此文  在build.gradle文件中添加一下依赖123compile &amp;apos;com.squareup.retrofit2:adapter-rxjava:2.3.0&amp;apos;compile &amp;apos;com.">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/blog/',
    scheme: 'Pisces',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: 'Author'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/blog/2018/08/06/Java/Java-Retrofit2使用/"/>





  <title>Java-Retrofit2使用 | 凌浩雨_博客</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="default">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/blog/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">凌浩雨_博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/blog/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            Home
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/blog/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            Archives
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/blog/blog/2018/08/06/Java/Java-Retrofit2使用/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="凌浩雨">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.jpeg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="凌浩雨_博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Java-Retrofit2使用</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2018-08-06T18:01:39+08:00">
                2018-08-06
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>###Java Retrofit2使用<br><strong>本文使用eclipse编辑器，gradle依赖jar，如若未配置此环境，请转<a href="http://www.jianshu.com/p/2495ffc49caa" target="_blank" rel="noopener">Java Eclipse配置gradle编译项目</a>配置好环境后再查看此文</strong></p>
<ol>
<li>在build.gradle文件中添加一下依赖<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">compile &apos;com.squareup.retrofit2:adapter-rxjava:2.3.0&apos;</span><br><span class="line">compile &apos;com.squareup.retrofit2:retrofit:2.3.0&apos;</span><br><span class="line">compile &apos;com.squareup.retrofit2:converter-gson:2.3.0&apos;</span><br></pre></td></tr></table></figure>
</li>
</ol>
<a id="more"></a>
<ol start="2">
<li><p>定义java bean,bean中的变量名要与返回的json数据中的key保持一致，否则会匹配不上。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line">// 1. 定义java bean</span><br><span class="line">	/**</span><br><span class="line">	 * Java Bean</span><br><span class="line">	 */</span><br><span class="line">	public class Info &#123;</span><br><span class="line">		int error_code; // 状态码</span><br><span class="line">		String reason; // 返回状态文字</span><br><span class="line">		Result result; // 页面URL</span><br><span class="line"></span><br><span class="line">		@Override</span><br><span class="line">		public String toString() &#123;</span><br><span class="line">			return &quot;Info [error_code=&quot; + error_code + &quot;, reason=&quot; + reason + &quot;, result=&quot; + result.toString() + &quot;]&quot;;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	/**</span><br><span class="line">	 * Java Bean</span><br><span class="line">	 */</span><br><span class="line">	public class Result &#123;</span><br><span class="line">		String h5url;</span><br><span class="line">		String h5weixin;</span><br><span class="line"></span><br><span class="line">		@Override</span><br><span class="line">		public String toString() &#123;</span><br><span class="line">			return &quot;Result [h5url=&quot; + h5url + &quot;, h5weixin=&quot; + h5weixin + &quot;]&quot;;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p>定义接口。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">static String url = &quot;http://v.juhe.cn/&quot;; // 请求链接</span><br><span class="line">static String KEY = &quot;9488373060c8483a3ef6333353fdc7fe&quot;; // 请求参数</span><br><span class="line">// 2. 定义接口</span><br><span class="line">public interface InfoService&#123;</span><br><span class="line">	@GET(&quot;wepiao/query&quot;)</span><br><span class="line">	Call&lt;Info&gt; getInfo(</span><br><span class="line">			@Query(value = &quot;key&quot;)</span><br><span class="line">			String key</span><br><span class="line">	);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
</ol>
<p>4.获取Retrofit实例<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">// 3. 获取实例</span><br><span class="line">Retrofit retrofit = new Retrofit.Builder()</span><br><span class="line">		// 设置OKHttpClient,如果不设置会提供一个默认的</span><br><span class="line">		.client(new OkHttpClient())</span><br><span class="line">		//设置baseUrl</span><br><span class="line">		.baseUrl(url)</span><br><span class="line">		//添加Gson转换器</span><br><span class="line">		.addConverterFactory(GsonConverterFactory.create())</span><br><span class="line">		.build();</span><br></pre></td></tr></table></figure></p>
<ol start="5">
<li><p>执行retrofit.create方法</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">// 4. 执行retrofit.create方法</span><br><span class="line">InfoService infoService = retrofit.create(InfoService.class);</span><br></pre></td></tr></table></figure>
</li>
<li><p>执行同步请求</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">// 5. 执行请求</span><br><span class="line">Call&lt;Info&gt; call = infoService.getInfo(KEY);</span><br><span class="line">Response&lt;Info&gt; response = call.execute();</span><br><span class="line"></span><br><span class="line">// 6. 判断是否成功，成功则打印出数据</span><br><span class="line">if (response.isSuccessful()) &#123;</span><br><span class="line">	Info info = response.body();</span><br><span class="line">	System.out.println(info.toString());</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p>执行异步请求</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">// 5. 执行请求</span><br><span class="line">Call&lt;Info&gt; call = infoService.getInfo(KEY);</span><br><span class="line">call.enqueue(new Callback&lt;RetrofitTest2.Info&gt;() &#123;</span><br><span class="line">	</span><br><span class="line">	public void onResponse(Call&lt;Info&gt; call, Response&lt;Info&gt; response) &#123;</span><br><span class="line">		Info info = response.body();</span><br><span class="line">		System.out.println(info);</span><br><span class="line">	&#125;</span><br><span class="line">	</span><br><span class="line">	public void onFailure(Call&lt;Info&gt; call, Throwable t) &#123;</span><br><span class="line">		System.out.println(t.getMessage());</span><br><span class="line">	&#125;</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>
</li>
</ol>
<p>retrofit注解：</p>
<p>方法注解，包含@GET、@POST、@PUT、@DELETE、@PATH、@HEAD、@OPTIONS、@HTTP。<br>标记注解，包含@FormUrlEncoded、@Multipart、@Streaming。<br>参数注解，包含@Query,@QueryMap、@Body、@Field，@FieldMap、@Part，@PartMap。<br>其他注解，@Path、@Header,@Headers、@Url。<br><strong>几种特殊的注解</strong><br>@HTTP：可以替代其他方法的任意一种<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line">  * method 表示请的方法，不区分大小写</span><br><span class="line">  * path表示路径</span><br><span class="line">  * hasBody表示是否有请求体</span><br><span class="line">  */</span><br><span class="line"> @HTTP(method = &quot;get&quot;, path = &quot;users/&#123;user&#125;&quot;, hasBody = false)</span><br><span class="line"> Call&lt;ResponseBody&gt; getFirstBlog(@Path(&quot;user&quot;) String user);</span><br></pre></td></tr></table></figure></p>
<p>@Url：使用全路径复写baseUrl，适用于非统一baseUrl的场景。<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">@GET</span><br><span class="line">Call&lt;ResponseBody&gt; v3(@Url String url);</span><br></pre></td></tr></table></figure></p>
<p>@Streaming:用于下载大文件<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">@Streaming</span><br><span class="line">@GET</span><br><span class="line">Call&lt;ResponseBody&gt; downloadFileWithDynamicUrlAsync(@Url String fileUrl);</span><br></pre></td></tr></table></figure></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">ResponseBody body = response.body();</span><br><span class="line">long fileSize = body.contentLength();</span><br><span class="line">InputStream inputStream = body.byteStream();</span><br></pre></td></tr></table></figure>
<p><strong>常用注解</strong><br>@Path：URL占位符，用于替换和动态更新,相应的参数必须使用相同的字符串被@Path进行注释<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">@GET(&quot;group/&#123;id&#125;/users&quot;)</span><br><span class="line">Call&lt;List&lt;User&gt;&gt; groupList(@Path(&quot;id&quot;) int groupId);</span><br><span class="line">//--&gt; http://baseurl/group/groupId/users</span><br><span class="line"></span><br><span class="line">//等同于：</span><br><span class="line">@GET</span><br><span class="line">Call&lt;List&lt;User&gt;&gt; groupListUrl(</span><br><span class="line">      @Url String url</span><br><span class="line">);</span><br></pre></td></tr></table></figure></p>
<p>@Query,@QueryMap:查询参数，用于GET查询,需要注意的是@QueryMap可以约定是否需要encode<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">@GET(&quot;group/users&quot;)</span><br><span class="line">Call&lt;List&lt;User&gt;&gt; groupList(@Query(&quot;id&quot;) int groupId);</span><br><span class="line">//--&gt; http://baseurl/group/users?id=groupId</span><br></pre></td></tr></table></figure></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Call&lt;List&lt;News&gt;&gt; getNews((@QueryMap(encoded=true) Map&lt;String, String&gt; options);</span><br></pre></td></tr></table></figure>
<p>@Body:用于POST请求体，将实例对象根据转换方式转换为对应的json字符串参数，这个转化方式是GsonConverterFactory定义的。<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">@POST(&quot;add&quot;)</span><br><span class="line">Call&lt;List&lt;User&gt;&gt; addUser(@Body User user);</span><br></pre></td></tr></table></figure></p>
<p>@Field，@FieldMap:Post方式传递简单的键值对,需要添加@FormUrlEncoded表示表单提交Content-Type:application/x-www-form-urlencoded.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">@FormUrlEncoded</span><br><span class="line">@POST(&quot;user/edit&quot;)</span><br><span class="line">Call&lt;User&gt; updateUser(@Field(&quot;first_name&quot;) String first, @Field(&quot;last_name&quot;) String last);</span><br></pre></td></tr></table></figure></p>
<p>@Part，@PartMap：用于POST文件上传<br>其中@Part MultipartBody.Part代表文件，@Part(“key”) RequestBody代表参数<br>需要添加@Multipart表示支持文件上传的表单，Content-Type: multipart/form-data.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">@Multipart</span><br><span class="line">@POST(&quot;upload&quot;)</span><br><span class="line">Call&lt;ResponseBody&gt; upload(@Part(&quot;description&quot;) RequestBody description, @Part MultipartBody.Part file);</span><br></pre></td></tr></table></figure></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">// https://github.com/iPaulPro/aFileChooser/blob/master/aFileChooser/src/com/ipaulpro/afilechooser/utils/FileUtils.java</span><br><span class="line">    // use the FileUtils to get the actual file by uri</span><br><span class="line">    File file = FileUtils.getFile(this, fileUri);</span><br><span class="line"></span><br><span class="line">    // create RequestBody instance from file</span><br><span class="line">    RequestBody requestFile =</span><br><span class="line">            RequestBody.create(MediaType.parse(&quot;multipart/form-data&quot;), file);</span><br><span class="line"></span><br><span class="line">    // MultipartBody.Part is used to send also the actual file name</span><br><span class="line">    MultipartBody.Part body =</span><br><span class="line">            MultipartBody.Part.createFormData(&quot;picture&quot;, file.getName(), requestFile);</span><br><span class="line"></span><br><span class="line">    // add another part within the multipart request</span><br><span class="line">    String descriptionString = &quot;hello, this is description speaking&quot;;</span><br><span class="line">    RequestBody description =</span><br><span class="line">            RequestBody.create(</span><br><span class="line">                    MediaType.parse(&quot;multipart/form-data&quot;), descriptionString);</span><br></pre></td></tr></table></figure>
<p>@Header：header处理，不能被互相覆盖，用于修饰参数<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">//动态设置Header值</span><br><span class="line">@GET(&quot;user&quot;)</span><br><span class="line">Call&lt;User&gt; getUser(@Header(&quot;Authorization&quot;) String authorization)</span><br></pre></td></tr></table></figure></p>
<p>等同于<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">//静态设置Header值</span><br><span class="line">@Headers(&quot;Authorization: authorization&quot;)//这里authorization就是上面方法里传进来变量的值</span><br><span class="line">@GET(&quot;widget/list&quot;)</span><br><span class="line">Call&lt;User&gt; getUser()</span><br></pre></td></tr></table></figure></p>
<p>@Headers 用于修饰方法,用于设置多个Header值<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">@Headers(&#123;</span><br><span class="line">    &quot;Accept: application/vnd.github.v3.full+json&quot;,</span><br><span class="line">    &quot;User-Agent: Retrofit-Sample-App&quot;</span><br><span class="line">&#125;)</span><br><span class="line">@GET(&quot;users/&#123;username&#125;&quot;)</span><br><span class="line">Call&lt;User&gt; getUser(@Path(&quot;username&quot;) String username);</span><br></pre></td></tr></table></figure></p>
<p><a href="http://git.oschina.net/zaitingma/codes/kuqv0267eth9s3gpocx5y93" target="_blank" rel="noopener">代码下载</a></p>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/blog/2018/08/06/Java/Java-Retrofit2使用--自定义转换器/" rel="next" title="Java-Retrofit2使用--自定义转换器">
                <i class="fa fa-chevron-left"></i> Java-Retrofit2使用--自定义转换器
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/blog/2018/08/06/Java/Java-RxJava学习使用/" rel="prev" title="Java-RxJava学习使用">
                Java-RxJava学习使用 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      

      <section class="site-overview-wrap sidebar-panel sidebar-panel-active">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/blog/images/avatar.jpeg"
                alt="凌浩雨" />
            
              <p class="site-author-name" itemprop="name">凌浩雨</p>
              <p class="site-description motion-element" itemprop="description">专业从事于移动端开发，Android与iOS均有涉及，主做Android开发与React Native开发</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/blog/archives/">
              
                  <span class="site-state-item-count">393</span>
                  <span class="site-state-item-name">posts</span>
                </a>
              </div>
            

            

            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">凌浩雨</span>

  
</div>


  <div class="powered-by">Powered by <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a></div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">Theme &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Pisces</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/blog/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/blog/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/blog/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/blog/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/blog/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/blog/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/blog/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/blog/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
